package cn.hdu.liang.typeinfo;

import java.util.ArrayList;

public class Staff extends ArrayList<Position> {

    public void add(String title, Person person) {
        add(new Position(title, person));
    }

    public void add(String... titles) {
        for(String title : titles) {
            add(new Position(title));
        }
    }

    public Staff(String... titles) {
        add(titles);
    }

    public boolean positionAvailable(String title) {
        for(Position position : this) {
            if(position.getTitle().equals(title) && position.getPerson() == Person.NULL) {
                return true;
            }
        }
        return false;
    }

    public void fillPosition(String title, Person hire) {
        for(Position position : this) {
            if(position.getTitle().equals(title) && position.getPerson() == Person.NULL) {
                position.setPerson(hire);
                return;
            }
        }
        throw new RuntimeException("Position " + title + " not available");
    }

    public static void main(String[] args) {
        Staff staff = new Staff("董事长", "CTO",
                "市场经理", "项目经理",
                "架构师", "软件工程师",
                "软件工程师", "软件工程师",
                "软件工程师", "测试工程师",
                "技术支持");

        staff.fillPosition("董事长", new Person("Me", "Last", "The Top, Lonely At"));

        staff.fillPosition("架构师", new Person("Janet", "Planner", "The Burbs"));

        if(staff.positionAvailable("软件工程师")) {
            staff.fillPosition("软件工程师", new Person("Bob", "Coder", "Bright Light City"));
        }

        for(Position s : staff) {
            System.out.println(s);
        }
    }

}
